package nl.windgazer.arachne.mixins.facebook;

import nl.windgazer.arachne.services.ArachneRenderSupport;
import nl.windgazer.arachne.services.facebook.FacebookShareMediumType;

import org.apache.tapestry5.RenderSupport;
import org.apache.tapestry5.annotations.Environmental;
import org.apache.tapestry5.annotations.Parameter;
import org.apache.tapestry5.annotations.SetupRender;

public class FacebookShare {

	//Injects and Persists

	@Environmental
	private ArachneRenderSupport _ars;

	@Environmental
	private RenderSupport _rs;

	//Properties and Parameters

	@Parameter(required=true,name="fbtitle",defaultPrefix="literal")
	private String title;

	@Parameter(required=true,name="fbdesc",defaultPrefix="literal")
	private String description;

	@Parameter(required=false,name="fbimage",defaultPrefix="literal")
	private String image;

	@Parameter(required=false,name="fbtype",defaultPrefix="literal")
	private FacebookShareMediumType type;

	//Components
	//Events

	@SetupRender
	void setupMetaTags() {
		_ars.addMetaTag("title", title);
		_ars.addMetaTag("description", description);
		if (image!=null) {
			_ars.addLink("image_src", image);
		}
		if (type!=null) {
			_ars.addMetaTag("medium", type.toString());
		}
		//TODO: Add link to FB-share script @ http://static.ak.fbcdn.net/connect.php/js/FB.Share
		_rs.addScriptLink("http://static.ak.fbcdn.net/connect.php/js/FB.Share");
	}

	//Other (check for business-logic, it should not remain here)

}
